import LevelInitBase from "../LevelCommon/LevelInitBase";
import LevelControl8 from "../LevelControl/LevelControl8";
import RoomControl from "../LevelCommon/RoomControl";
import { utils } from "../../utils/CommonUtil";
import FocusParentObj from "../Prefabs/InteractivObj/Common/FocusParentObj";
import PasswordLock from "../Prefabs/InteractivObj/Password/PasswordLock";
import PasswordKey from "../Prefabs/InteractivObj/Password/PasswordKey";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import FluorescentObj from "../Prefabs/InteractivObj/FluorescentObj/FluorescentObj";
import CallToLevel from "../Prefabs/CallToLevel";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import MoveCubePos from "../Prefabs/InteractivObj/MoveCubeLock/MoveCubePos";
import MoveCubeLock from "../Prefabs/InteractivObj/MoveCubeLock/MoveCubeLock";
import MoveCube from "../Prefabs/InteractivObj/MoveCubeLock/MoveCube";
import MoveCubeDir from "../Prefabs/InteractivObj/MoveCubeLock/MoveCubeDir";
import PhysPassLock from "../Prefabs/InteractivObj/PhysPassLock/PhysPassLock";
import PhysPassKey from "../Prefabs/InteractivObj/PhysPassLock/PhysPassKey";
import GamePropObj from "../Prefabs/InteractivObj/Common/GamePropObj";
import EnumData from "../../Enum/EnumData";

export default class LevelInit8 extends LevelInitBase {
    private room1: Laya.Sprite3D;

    private container: Laya.Sprite3D;

    public startInitDetail() {
        this.levelRoot.addComponent(LevelControl8);
        this.room1 = this.LevelObjs.getChildByName("room1") as Laya.Sprite3D;
        this.room1.addComponent(RoomControl);
        this.container = this.room1.getChildByName("Container") as Laya.Sprite3D;
        let walls = this.room1.getChildByName("walls") as Laya.Sprite3D;

        //#region wall1
        let wall1 = walls.getChildByName("wall1") as Laya.Sprite3D;
        let drawFocus = wall1.getChildByName("drawFocus");
        utils.CommonUtils.CustomAddComponent(drawFocus, FocusParentObj);

        let draw = drawFocus.getChildByName("draw");
        let RotateObj_darw = utils.CommonUtils.CustomAddComponent(draw, RotateObj) as RotateObj;
        RotateObj_darw.IsRotateOnce = true;
        RotateObj_darw.VoiceName = "move";
        RotateObj_darw.targetRotate = new Laya.Vector3(0, -180, 0);

        let drawObj = draw.getChildByName("drawObj");
        let hua2_touming = drawObj.getChildByName("hua2_touming");
        let FluorescentObj_drawObj = utils.CommonUtils.CustomAddComponent(hua2_touming, FluorescentObj) as FluorescentObj;
        FluorescentObj_drawObj.needPropId = 42;
        FluorescentObj_drawObj.isShouldUse = true;

        for (let index = 0; index < drawObj.numChildren; index++) {
            let corner = drawObj.getChildAt(index);
            utils.CommonUtils.CustomAddComponent(corner, CallToLevel);
        }

        let GameObject = draw.getChildByName("GameObject");
        utils.CommonUtils.CustomAddComponent(GameObject, CallToLevel);

        let endGate = wall1.getChildByName("endGate");
        utils.CommonUtils.CustomAddComponent(endGate, CallToLevel);

        let dianti = wall1.getChildByName("dianti");
        utils.CommonUtils.CustomAddComponent(dianti, FocusParentObj);

        let Box013 = dianti.getChildByName("Box013");
        let MoveObj_Box013 = utils.CommonUtils.CustomAddComponent(Box013, MoveObj) as MoveObj;
        MoveObj_Box013.VoiceName = "move";
        MoveObj_Box013.targetPos = new Laya.Vector3(6.602669, 0, 0.4379469);

        let GameObject2 = Box013.getChildByName("GameObject");
        utils.CommonUtils.CustomAddComponent(GameObject2, CallToLevel);

        let Box014 = dianti.getChildByName("Box014");
        let MoveObj_Box014 = utils.CommonUtils.CustomAddComponent(Box014, MoveObj) as MoveObj;
        MoveObj_Box014.VoiceName = "move";
        MoveObj_Box014.targetPos = new Laya.Vector3(6.602668, -3, 0.4379469);

        let MoveCubeLock_obj = Box014.getChildByName("MoveCubeLock");
        utils.CommonUtils.CustomAddComponent(MoveCubeLock_obj, MoveCubeLock);

        let moveCubes = new Array<MoveCube>();
        for (let index = 0; index < 7; index++) {
            let moveCubeObj = MoveCubeLock_obj.getChildAt(index);
            let moveCube = utils.CommonUtils.CustomAddComponent(moveCubeObj, MoveCube);
            moveCubes.push(moveCube);
        }

        moveCubes[0].selectColor = new Laya.Vector4(1, 0, 0, 0);
        moveCubes[0].curMoveCubePos.push(new MoveCubePos(2, 1));
        moveCubes[0].curMoveCubePos.push(new MoveCubePos(3, 1));

        moveCubes[1].curMoveCubePos.push(new MoveCubePos(4, 3));

        moveCubes[2].curMoveCubePos.push(new MoveCubePos(4, 1));

        moveCubes[3].selectColor = new Laya.Vector4(1, 0.7853516, 0, 0);
        moveCubes[3].curMoveCubePos.push(new MoveCubePos(1, 3));
        moveCubes[3].endPos = new MoveCubePos(4, 3);

        moveCubes[4].curMoveCubePos.push(new MoveCubePos(2, 2));

        moveCubes[5].curMoveCubePos.push(new MoveCubePos(4, 2));

        moveCubes[6].curMoveCubePos.push(new MoveCubePos(1, 1));


        let moveCubeDir = new Array<MoveCubeDir>();
        for (let index = 8; index < 12; index++) {
            let moveCubeObj = MoveCubeLock_obj.getChildAt(index);
            let moveCubeDirCom = utils.CommonUtils.CustomAddComponent(moveCubeObj, MoveCubeDir) as MoveCubeDir ;
            moveCubeDir.push(moveCubeDirCom);
        }
        moveCubeDir[0].curDir = EnumData.MoveCubeDirEnum.up;
        moveCubeDir[1].curDir = EnumData.MoveCubeDirEnum.left;
        moveCubeDir[2].curDir = EnumData.MoveCubeDirEnum.right;
        moveCubeDir[3].curDir = EnumData.MoveCubeDirEnum.bottom;

        let GameObject_1 = Box014.getChildByName("GameObject (1)");
        utils.CommonUtils.CustomAddComponent(GameObject_1, CallToLevel);

        //#endregion

        //#region wall2
        let wall2 = walls.getChildByName("wall2") as Laya.Sprite3D;
        let box_props = wall2.getChildByName("box_props");
        (box_props.getChildAt(0).getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider).enabled = false;
        utils.CommonUtils.CustomAddComponent(box_props,FocusParentObj);

        let door_props = box_props.getChildByName("box_props").getChildByName("door_props");
        let RotateObj_door_props = utils.CommonUtils.CustomAddComponent(door_props,RotateObj) as RotateObj;
        RotateObj_door_props.targetRotate = new Laya.Vector3(0,0,-90);
        RotateObj_door_props.VoiceName = "openGate";
        RotateObj_door_props.IsRotateOnce = true;

        let door_guang = door_props.getChildByName("door_guang");
        let door_guang_collider = door_guang.getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider;
        door_guang_collider.enabled= false;

        let door_guang_mima01 = door_props.getChildByName("door_guang_mima01");
        door_guang_mima01.active = true;
        let FluorescentObj_door_guang = utils.CommonUtils.CustomAddComponent(door_guang_mima01,FluorescentObj) as FluorescentObj;
        FluorescentObj_door_guang.needPropId = 38;

        let password_BOX0 = door_props.getChildByName("password BOX0");
        let PhysPassLock_password_BOX0 = utils.CommonUtils.CustomAddComponent(password_BOX0,PhysPassLock) as PhysPassLock;
        PhysPassLock_password_BOX0.correctPassInde.push(4);
        PhysPassLock_password_BOX0.correctPassInde.push(4);
        PhysPassLock_password_BOX0.correctPassInde.push(5);

        for (let index = 0; index < password_BOX0.numChildren; index++) {
            let physPassKeyObj = password_BOX0.getChildAt(index).getChildAt(0);
            let physPassKey = utils.CommonUtils.CustomAddComponent(physPassKeyObj,PhysPassKey) as PhysPassKey;
            physPassKey.isRotateY = true;
            physPassKey.rotateAngle = -45;
        }

        let box_props001 = wall2.getChildByName("box_props001");
         (box_props001.getChildAt(0).getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider).enabled = false;
        utils.CommonUtils.CustomAddComponent(box_props001,FocusParentObj);

        let Plane001 =  box_props001.getChildByName("box_props001").getChildByName("Plane001");
        let GamePropObj_Plane001 = utils.CommonUtils.CustomAddComponent(Plane001,GamePropObj)as GamePropObj;
        GamePropObj_Plane001.gamePropId = 63;

        let door_props001 = box_props001.getChildByName("box_props001").getChildByName("door_props001");
        let RotateObj_door_props001 = utils.CommonUtils.CustomAddComponent(door_props001,RotateObj) as RotateObj;
        RotateObj_door_props001.targetRotate = new Laya.Vector3(0,0,-90);
        RotateObj_door_props001.VoiceName = "openGate";
        RotateObj_door_props001.IsRotateOnce = true;

        
        let door_guang001 = door_props001.getChildByName("door_guang001");
        let door_guang001_collider = door_guang001.getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider;
        door_guang001_collider.enabled= false;

        let door_guang_mima02 = door_props001.getChildByName("door_guang_mima02");
        door_guang_mima02.active = true;
        let FluorescentObj_door_guang_mima02 = utils.CommonUtils.CustomAddComponent(door_guang_mima02,FluorescentObj) as FluorescentObj;
        FluorescentObj_door_guang_mima02.needPropId = 38;

        let password_BOX1 = door_props001.getChildByName("password BOX1");
        let PhysPassLock_password_BOX1 = utils.CommonUtils.CustomAddComponent(password_BOX1,PhysPassLock) as PhysPassLock;
        PhysPassLock_password_BOX1.correctPassInde.push(1);
        PhysPassLock_password_BOX1.correctPassInde.push(6);
        PhysPassLock_password_BOX1.correctPassInde.push(2);

        for (let index = 0; index < password_BOX1.numChildren; index++) {
            let physPassKeyObj = password_BOX1.getChildAt(index).getChildAt(0);
            let physPassKey = utils.CommonUtils.CustomAddComponent(physPassKeyObj,PhysPassKey) as PhysPassKey;
            physPassKey.isRotateY = true;
            physPassKey.rotateAngle = -45;
        }

        let box_props002 = wall2.getChildByName("box_props002");
        (box_props002.getChildAt(0).getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider).enabled = false;
        utils.CommonUtils.CustomAddComponent(box_props002,FocusParentObj);

        let Object005 =  box_props002.getChildByName("box_props002").getChildByName("Object005");
        let GamePropObj_Object005 = utils.CommonUtils.CustomAddComponent(Object005,GamePropObj)as GamePropObj;
        GamePropObj_Object005.gamePropId = 39;

        let door_props002 = box_props002.getChildByName("box_props002").getChildByName("door_props002");
        let RotateObj_door_props002 = utils.CommonUtils.CustomAddComponent(door_props002,RotateObj) as RotateObj;
        RotateObj_door_props002.targetRotate = new Laya.Vector3(0,0,-90);
        RotateObj_door_props002.VoiceName = "openGate";
        RotateObj_door_props002.IsRotateOnce = true;

        let door_guang002 = door_props002.getChildByName("door_guang002");
        let door_guang002_collider = door_guang002.getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider;
        door_guang002_collider.enabled= false;

        let door_guang_mima03 = door_props002.getChildByName("door_guang_mima03");
        let FluorescentObj_door_guang_mima03 = utils.CommonUtils.CustomAddComponent(door_guang_mima03,FluorescentObj) as FluorescentObj;
        door_guang_mima03.active = true;
        FluorescentObj_door_guang_mima03.needPropId = 38;

        let password_BOX2 = door_props002.getChildByName("password BOX2");
        let PhysPassLock_password_BOX2 = utils.CommonUtils.CustomAddComponent(password_BOX2,PhysPassLock) as PhysPassLock;
        PhysPassLock_password_BOX2.correctPassInde.push(5);
        PhysPassLock_password_BOX2.correctPassInde.push(2);
        PhysPassLock_password_BOX2.correctPassInde.push(5);

        for (let index = 0; index < password_BOX2.numChildren; index++) {
            let physPassKeyObj = password_BOX2.getChildAt(index).getChildAt(0);
            let physPassKey = utils.CommonUtils.CustomAddComponent(physPassKeyObj,PhysPassKey) as PhysPassKey;
            physPassKey.isRotateY = true;
            physPassKey.rotateAngle = -45;
        }
        
        let box_props003 = wall2.getChildByName("box_props003");
        (box_props003.getChildAt(0).getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider).enabled = false;
        utils.CommonUtils.CustomAddComponent(box_props003,FocusParentObj);

        let laguan =  box_props003.getChildByName("box_props003").getChildByName("laguan");
        let GamePropObj_laguan = utils.CommonUtils.CustomAddComponent(laguan,GamePropObj)as GamePropObj;
        GamePropObj_laguan.gamePropId = 40;

        let door_props003 = box_props003.getChildByName("box_props003").getChildByName("door_props003");
        let RotateObj_door_props003 = utils.CommonUtils.CustomAddComponent(door_props003,RotateObj) as RotateObj;
        RotateObj_door_props003.targetRotate = new Laya.Vector3(0,0,-90);
        RotateObj_door_props003.VoiceName = "openGate";
        RotateObj_door_props003.IsRotateOnce = true;
        

        let door_guang003 = door_props003.getChildByName("door_guang003");
        let door_guang003_collider = door_guang003.getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider;
        door_guang003_collider.enabled= false;

        let door_guang_mima04 = door_props003.getChildByName("door_guang_mima04");
        door_guang_mima04.active = true;
        let FluorescentObj_door_guang_mima04 = utils.CommonUtils.CustomAddComponent(door_guang_mima04,FluorescentObj) as FluorescentObj;
        FluorescentObj_door_guang_mima04.needPropId = 38;

        let password_BOX3 = door_props003.getChildByName("password BOX3");
        let PhysPassLock_password_BOX3 = utils.CommonUtils.CustomAddComponent(password_BOX3,PhysPassLock) as PhysPassLock;
        PhysPassLock_password_BOX3.correctPassInde.push(4);
        PhysPassLock_password_BOX3.correctPassInde.push(1);
        PhysPassLock_password_BOX3.correctPassInde.push(4);

        for (let index = 0; index < password_BOX3.numChildren; index++) {
            let physPassKeyObj = password_BOX3.getChildAt(index).getChildAt(0);
            let physPassKey = utils.CommonUtils.CustomAddComponent(physPassKeyObj,PhysPassKey) as PhysPassKey;
            physPassKey.isRotateY = true;
            physPassKey.rotateAngle = -45;
        }

        let jinianpin = wall2.getChildByName("SM_Prop_Gas_Table_01").getChildByName("jinianpin");
        let GamePropObj_jinianpin = utils.CommonUtils.CustomAddComponent(jinianpin,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin.gamePropId = 11;

        //#endregion

        //#region wall3
        let wall3 = walls.getChildByName("wall3") as Laya.Sprite3D;
        let Object004 = wall3.getChildByName("Object004");
        utils.CommonUtils.CustomAddComponent(Object004,FocusParentObj);

        let SM_Item_Air_Horn_01 = Object004.getChildByName("SM_Item_Air_Horn_01");
        let GamePropObj_SM_Item_Air_Horn_01 = utils.CommonUtils.CustomAddComponent(SM_Item_Air_Horn_01,GamePropObj) as GamePropObj;
        GamePropObj_SM_Item_Air_Horn_01.gamePropId = 38;
        //#endregion

        //#region wall4
        let wall4 = walls.getChildByName("wall4") as Laya.Sprite3D;

        let computer = wall4.getChildByName("computer") as Laya.Sprite3D;

        let _switch = computer.getChildByName("machineGate").getChildByName("switch");
        let RotateObj_switch = utils.CommonUtils.CustomAddComponent(_switch,RotateObj) as RotateObj;
        RotateObj_switch.IsRotateOnce = true;
        RotateObj_switch.targetRotate = new Laya.Vector3(0,152,0);

        utils.CommonUtils.CustomAddComponent(computer, FocusParentObj);
        let Password_machine = computer.getChildByName("Password machine") as Laya.Sprite3D;
        let passwordLock = utils.CommonUtils.CustomAddComponent(Password_machine, PasswordLock) as PasswordLock;
        passwordLock.passWord = "2136";

        let keyBoard = Password_machine.getChildByName("keyBoard") as Laya.Sprite3D;
        for (let index = 0; index < keyBoard.numChildren; index++) {
            let child = keyBoard.getChildAt(index);
            let passwordKey = utils.CommonUtils.CustomAddComponent(child, PasswordKey) as PasswordKey;
            if (child.name == "enter") {
                passwordKey.keyValue = "enter"
            } else {
                passwordKey.keyValue = (index + 1) + "";
            }
        }
        let Cylinder001 = computer.getChildByName("Cylinder001");
        let GamePropObj_Cylinder001 = utils.CommonUtils.CustomAddComponent(Cylinder001,GamePropObj) as GamePropObj;
        GamePropObj_Cylinder001.gamePropId = 41;
        
        let jinianpin1 = computer.getChildByName("jinianpin (1)");
        let GamePropObj_jinianpin1 = utils.CommonUtils.CustomAddComponent(jinianpin1,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin1.gamePropId =11;

        let jinianpin2 = wall4.getChildByName("SM_Prop_Bed_Bunk_01").getChildByName("jinianpin");
        let GamePropObj_jinianpin2 = utils.CommonUtils.CustomAddComponent(jinianpin2,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin2.gamePropId = 11;

        let Plane002 = wall4.getChildByName("Plane002");
        utils.CommonUtils.CustomAddComponent(Plane002,FocusParentObj);
        
        //#endregion
    }
}